package com.example.springboot.oss.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.region.Region;
import com.qcloud.cos.ClientConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CosConfig {

    @Bean
    public COSClient cosClient() {
        // 初始化用户身份信息（secretId, secretKey）。
        BasicCOSCredentials cred = new BasicCOSCredentials("AKIDHZosmT4VlncJn4XnrhIhsrc9UdaO1Wts", "tZ4VloXBcrY8Xkmd9VfcfrvorwwITRCi");

        // 设置 bucket 的地域
        Region region = new Region("ap-chengdu");

        // 设置客户端配置
        ClientConfig clientConfig = new ClientConfig(region);

        // 生成 cos 客户端
        return new COSClient(cred, clientConfig);
    }
}